package com.example.controller;

import com.example.common.Result;
import com.example.service.WebSocketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * WebSocket测试控制器
 * 用于测试WebSocket功能
 */
@RestController
@RequestMapping("/api/websocket")
@CrossOrigin
public class WebSocketTestController {
    
    @Autowired
    private WebSocketService webSocketService;
    
    /**
     * 发送测试广播消息
     */
    @PostMapping("/test/broadcast")
    public Result<String> sendTestBroadcast(@RequestParam String message) {
        webSocketService.sendSystemNotification("测试广播", message, "info");
        return Result.success("广播消息发送成功");
    }
    
    /**
     * 发送测试私人消息
     */
    @PostMapping("/test/private")
    public Result<String> sendTestPrivate(@RequestParam Long userId, @RequestParam String message) {
        webSocketService.sendPrivateNotification(userId, "测试私人消息", message, null, 1L, "系统管理员");
        return Result.success("私人消息发送成功");
    }
    
    /**
     * 发送测试通知消息
     */
    @PostMapping("/test/notice")
    public Result<String> sendTestNotice(@RequestParam String title, @RequestParam String content) {
        webSocketService.sendNoticeNotification(title, content, null, 1L, "系统管理员");
        return Result.success("通知消息发送成功");
    }
}
